import numpy as np

# 二维数组转矩阵
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
             dtype=np.int64)  # 更改元素类型
print(a)
print(a.shape)
print(a.ndim)
print(a.size)
print(a.dtype)

# 定义3行4列全零矩阵
b = np.zeros((3, 4))
print(b)
print(b.shape)
print(b.ndim)
print(b.size)
print(b.dtype)

# 定义3行4列全1矩阵
c = np.ones((3, 4))
print(c)
print(c.shape)
print(c.ndim)
print(c.size)
print(c.dtype)

# 定义3行4列全x矩阵
d = np.full((3, 4), 7)
print(d)
print(d.shape)
print(d.ndim)
print(d.size)
print(d.dtype)

# 定义一个3行4列空矩阵
e = np.empty((3, 4))
print(e)
print(e.shape)
print(e.ndim)
print(e.size)
print(e.dtype)

# 定义一个10到20步长为2的矩阵
f = np.arange(10, 20, 2)
print(f)
print(f.shape)
print(f.ndim)
print(f.size)
print(f.dtype)
# 改变形状
g = f.reshape(5, 1)
print(g)
print(g.shape)
print(g.ndim)
print(g.size)
print(g.dtype)

# 生成一个10到20分五等分的矩阵
h = np.linspace(10, 20, 5)
print(h)
print(h.shape)
print(h.ndim)
print(h.size)
print(h.dtype)

# 随机矩阵
i = np.random.random((3, 4))
print(i)
print(i.shape)
print(i.ndim)
print(i.size)
print(i.dtype)